{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "initial_id",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-03-15T07:05:52.131266800Z",
     "start_time": "2024-03-15T07:05:52.054031600Z"
    },
    "collapsed": true,
    "jupyter": {
     "outputs_hidden": true
    }
   },
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import matplotlib.pyplot as plt\n",
    "import seaborn as sns\n",
    "import warnings\n",
    "import numpy as np\n",
    "from datetime import datetime\n",
    "from sklearn.preprocessing import LabelEncoder\n",
    "from collections import Counter\n",
    "from sklearn import preprocessing\n",
    "\n",
    "#设置为seaborn风格\n",
    "sns.set()\n",
    "#不显示警告\n",
    "warnings.filterwarnings(\"ignore\")\n",
    "plt.rcParams['font.sans-serif'] = ['SimHei']  #显示中文\n",
    "plt.rcParams['axes.unicode_minus'] = False  #用来正常显示负号"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "13239b100232f93f",
   "metadata": {
    "collapsed": false,
    "jupyter": {
     "outputs_hidden": false
    }
   },
   "source": [
    "# 行为特征"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "8c78eda7d12caa05",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-03-15T07:43:22.647528400Z",
     "start_time": "2024-03-15T07:42:50.702603300Z"
    },
    "collapsed": false,
    "jupyter": {
     "outputs_hidden": false
    }
   },
   "outputs": [],
   "source": [
    "actions = pd.read_csv('./CL_OR.csv')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "103037b6a0bcaab7",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-03-15T07:43:22.662942500Z",
     "start_time": "2024-03-15T07:43:22.648938100Z"
    },
    "collapsed": false,
    "jupyter": {
     "outputs_hidden": false
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>sku_ID</th>\n",
       "      <th>user_ID</th>\n",
       "      <th>request_time</th>\n",
       "      <th>channel</th>\n",
       "      <th>order_ID</th>\n",
       "      <th>order_date</th>\n",
       "      <th>order_time</th>\n",
       "      <th>quantity</th>\n",
       "      <th>type</th>\n",
       "      <th>promise</th>\n",
       "      <th>...</th>\n",
       "      <th>coupon_discount_per_unit</th>\n",
       "      <th>gift_item</th>\n",
       "      <th>dc_ori</th>\n",
       "      <th>dc_des</th>\n",
       "      <th>click_week</th>\n",
       "      <th>click_hour</th>\n",
       "      <th>order_week</th>\n",
       "      <th>order_hour</th>\n",
       "      <th>click_day</th>\n",
       "      <th>order_day</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>a234e08c57</td>\n",
       "      <td>4c3d6d10c2</td>\n",
       "      <td>2018-03-01 23:57:53</td>\n",
       "      <td>wechat</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>4.0</td>\n",
       "      <td>23.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1.0</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>6449e1fd87</td>\n",
       "      <td>-</td>\n",
       "      <td>2018-03-01 16:13:48</td>\n",
       "      <td>wechat</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>4.0</td>\n",
       "      <td>16.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1.0</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>09b70fcd83</td>\n",
       "      <td>2791ec4485</td>\n",
       "      <td>2018-03-01 22:10:51</td>\n",
       "      <td>wechat</td>\n",
       "      <td>e4874e2a00</td>\n",
       "      <td>2018-03-01</td>\n",
       "      <td>2018-03-01 14:08:33</td>\n",
       "      <td>1.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>-</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>24.0</td>\n",
       "      <td>40.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>22.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>14.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>09b70fcd83</td>\n",
       "      <td>eb0718c1c9</td>\n",
       "      <td>2018-03-01 16:34:08</td>\n",
       "      <td>wechat</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>4.0</td>\n",
       "      <td>16.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1.0</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>09b70fcd83</td>\n",
       "      <td>59f84cf342</td>\n",
       "      <td>2018-03-01 22:20:35</td>\n",
       "      <td>wechat</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>4.0</td>\n",
       "      <td>22.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1.0</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 25 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "       sku_ID     user_ID         request_time channel    order_ID  \\\n",
       "0  a234e08c57  4c3d6d10c2  2018-03-01 23:57:53  wechat         NaN   \n",
       "1  6449e1fd87           -  2018-03-01 16:13:48  wechat         NaN   \n",
       "2  09b70fcd83  2791ec4485  2018-03-01 22:10:51  wechat  e4874e2a00   \n",
       "3  09b70fcd83  eb0718c1c9  2018-03-01 16:34:08  wechat         NaN   \n",
       "4  09b70fcd83  59f84cf342  2018-03-01 22:20:35  wechat         NaN   \n",
       "\n",
       "   order_date           order_time  quantity  type promise  ...  \\\n",
       "0         NaN                  NaN       NaN   NaN     NaN  ...   \n",
       "1         NaN                  NaN       NaN   NaN     NaN  ...   \n",
       "2  2018-03-01  2018-03-01 14:08:33       1.0   2.0       -  ...   \n",
       "3         NaN                  NaN       NaN   NaN     NaN  ...   \n",
       "4         NaN                  NaN       NaN   NaN     NaN  ...   \n",
       "\n",
       "   coupon_discount_per_unit  gift_item  dc_ori  dc_des  click_week  \\\n",
       "0                       NaN        NaN     NaN     NaN         4.0   \n",
       "1                       NaN        NaN     NaN     NaN         4.0   \n",
       "2                       0.0        0.0    24.0    40.0         4.0   \n",
       "3                       NaN        NaN     NaN     NaN         4.0   \n",
       "4                       NaN        NaN     NaN     NaN         4.0   \n",
       "\n",
       "   click_hour  order_week  order_hour  click_day  order_day  \n",
       "0        23.0         NaN         NaN        1.0        NaN  \n",
       "1        16.0         NaN         NaN        1.0        NaN  \n",
       "2        22.0         4.0        14.0        1.0        1.0  \n",
       "3        16.0         NaN         NaN        1.0        NaN  \n",
       "4        22.0         NaN         NaN        1.0        NaN  \n",
       "\n",
       "[5 rows x 25 columns]"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "actions.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "7ced88d7e5cb4b64",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-03-15T07:43:23.305351Z",
     "start_time": "2024-03-15T07:43:22.975470Z"
    },
    "collapsed": false,
    "jupyter": {
     "outputs_hidden": false
    }
   },
   "outputs": [],
   "source": [
    "def get_actions(start_date, end_date):\n",
    "    return actions[\n",
    "        (actions['click_day'] >= start_date) & (actions['click_day'] < end_date)\n",
    "    ]\n",
    "\n",
    "\n",
    "actions_1 = get_actions(1, 5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "2ef92e69be45d1e6",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-03-15T07:44:15.389513Z",
     "start_time": "2024-03-15T07:44:15.345520900Z"
    },
    "collapsed": false,
    "jupyter": {
     "outputs_hidden": false
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1.0    967552\n",
       "4.0    611157\n",
       "3.0    585924\n",
       "2.0    535448\n",
       "Name: click_day, dtype: int64"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "actions_1['click_day'].value_counts()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "eb1344c3e49dac61",
   "metadata": {
    "collapsed": false,
    "jupyter": {
     "outputs_hidden": false
    }
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "394601eb6db4b8bf",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-03-15T07:44:04.323991400Z",
     "start_time": "2024-03-15T07:44:04.308800700Z"
    },
    "collapsed": false,
    "jupyter": {
     "outputs_hidden": false
    }
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5b9373c2fa9945d6",
   "metadata": {
    "collapsed": false,
    "jupyter": {
     "outputs_hidden": false
    }
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.19"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
